import re

import requests
import pymysql

url = 'https://api.web.360kan.com/v1/rank?cat=3&callback=__jp0'

# headers = {
#     'Cookie': '__guid=121874957.2510689742355462700.1709860404806.75; __huid=11vUX0TeGcXCbC%2B3YUl7%2BLTfqGBwzTH8zRpWfv8WqDW7U%3D; refer_scene=47010; ___sid=121874957.3981267888630621000.1715691127397.1343; monitor_count=6; __DC_gid=121874957.8607708.1709860404902.1715691516435.107',
#     'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
# }
res = requests.get(url)
data = res.content.decode()
# print(data)
datas = re.findall('"title":"(.*?)".*?"cover":"(https://p.*?\.qhimg.com/d/dy_.*?\.jpg)"', data)

# print(datas)
for i in datas:
    head_url = i[1]
    print(type(i[1]))
    print(head_url)
    head_res = requests.get(url=head_url)
    print(head_res.content)
    with open('../datas/code/head_img.jpg', 'wb') as f:
        f.write(head_res.content)
    break
